import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class TopPanel extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _TopPanel();
  }
}

class _TopPanel extends State<TopPanel> {
  Color starColor = Colors.white;

  Widget myIcon(String val,
      {List margin = const [0.0, 15.0],
      Color iconColor: Colors.white,
      Function myOnTap}) {
    Map<String, IconData> icons = {
      'chevron_left': Icons.chevron_left,
      'star_border': Icons.star_border,
      'share': Icons.share,
      'message': Icons.message,
      'more_horiz': Icons.more_horiz,
    };
    return Container(
        decoration: BoxDecoration(boxShadow: [
          BoxShadow(
            color: Color(0x11000000),
            blurRadius: 0.5,
          ),
        ]),
        margin: EdgeInsets.only(left: margin[0], right: margin[1]),
        child: GestureDetector(
          child: Icon(icons[val], color: iconColor),
          onTap: () {
            if (myOnTap != null) myOnTap();
          },
        ));
  }

  @override
  Widget build(BuildContext context) {
    void starTap() {
      setState(() {
        starColor = starColor == Colors.white ? Colors.yellow : Colors.white;
      });
    }

    return Container(
        width: MediaQuery.of(context).size.width,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            myIcon('chevron_left',
                margin: [10.0, 0.0], myOnTap: () => Navigator.pop(context)),
            Row(
              children: [
                myIcon('star_border',
                    iconColor: starColor, myOnTap: () => starTap()),
                myIcon('share'),
                myIcon('message'),
                myIcon('more_horiz'),
              ],
            )
          ],
        ));
  }
}
